package tmproject.hlhj.fhp.tmvote.network

import android.content.Context
import com.lzy.okgo.OkGo
import com.lzy.okgo.model.Response
import com.lzy.okrx.adapter.ObservableResponse
import io.reactivex.android.schedulers.AndroidSchedulers
import rx.Observable
import rx.schedulers.Schedulers
import tmproject.hlhj.fhp.tmvote.beans.*
import java.io.File

/**
 * Created by Never Fear   on 2018\8\13 0013.
Never More....
 */
object Apis {
    /*App颜色*/
    fun getAPPColor(): Observable<Response<AppColorBean>> {
        return OkGo.get<AppColorBean>(Urls.Base_Url+Urls.APP_COLOR)
                .converter(object :JsonConvert<AppColorBean>(){})
                .adapt(ObservableResponse<AppColorBean>())
                .subscribeOn(Schedulers.io())
    }
    /*活动列表*/
    fun getActiveList(page:Int,limit:Int): Observable<Response<VoteListBean>>? {
      return  OkGo.get<VoteListBean>(Urls.Base_Url+Urls.Active_List)
                .params("page",page)
                .params("limit",limit)
                .converter(object :JsonConvert<VoteListBean>(){})
                .adapt(ObservableResponse<VoteListBean>())
                .subscribeOn(Schedulers.io())

    }
    /*活动详情*/
    fun getVoteDetail(activity_id:Int,user_sign:String): Observable<Response<VotingBean>> {
        return OkGo.get<VotingBean>(Urls.Base_Url+Urls.Active_Detail)
                .params("activity_id",activity_id)
                .params("user_sign",user_sign)
                .converter(object :JsonConvert<VotingBean>(){})
                .adapt(ObservableResponse<VotingBean>())
                .subscribeOn(Schedulers.io())
    }
    /*获取选手列表*/

    fun getPlayerList(activity_id:Int,page:Int,pageSize:Int): Observable<Response<PlayerListBean>> {
        return OkGo.get<PlayerListBean>(Urls.Base_Url+Urls.Player_List)
                .params("activity_id",activity_id)
                .params("page",page)
                .params("limit",pageSize)
                .converter(object :JsonConvert<PlayerListBean>(){})
                .adapt(ObservableResponse<PlayerListBean>())
                .subscribeOn(Schedulers.io())
    }
    /*报名*/

    fun signUp(user_id:String,competitor_name:String,phone:String,profile:String,activity_id:String,
               pay_way:String?,avatar:File): Observable<Response<BaseBean>>? {
       return OkGo.post<BaseBean>(Urls.Base_Url+Urls.Sign_Up)
                .params("user_id",user_id)
                .params("competitor_name",competitor_name)
                .params("phone",phone)
                .params("profile",profile)
                .params("activity_id",activity_id)
                .params("pay_way", if (pay_way==null) "" else pay_way)
//                .params("pay_way","1")
                .params("avatar",avatar)
                .converter(object :JsonConvert<BaseBean>(){})
                .adapt(ObservableResponse<BaseBean>())
                .subscribeOn(Schedulers.io())
    }

    /*投票*/
    fun vote(competitor_id:String,user_id:String): Observable<Response<BaseBean>>? {
       return OkGo.get<BaseBean>(Urls.Base_Url+Urls.Vote)
                .params("competitor_id",competitor_id)
                .params("user_id",user_id)
                .converter(object :JsonConvert<BaseBean>(){})
                .adapt(ObservableResponse<BaseBean>())
                .subscribeOn(Schedulers.io())
    }

    /*搜索*/
    fun search(activity_id	:String,name:String): Observable<Response<SearchBean>>? {
       return OkGo.get<SearchBean>(Urls.Base_Url+Urls.Search)
                .params("activity_id",activity_id)
                .params("name",name)
                .converter(object :JsonConvert<SearchBean>(){})
                .adapt(ObservableResponse<SearchBean>())
                .subscribeOn(Schedulers.io())
    }
    /*获取支付方式*/
    fun getPayways(): Observable<Response<PayWaysBean>>? {
        return OkGo.get<PayWaysBean>(Urls.Base_Url+Urls.PayWays)
                .converter(object:JsonConvert<PayWaysBean>(){})
                .adapt(ObservableResponse<PayWaysBean>())
                .subscribeOn(Schedulers.io())
    }

    /*获取分享信息*/
    fun getShare(activity_id:Int): Observable<Response<ShareBean>> {
       return OkGo.get<ShareBean>(Urls.Base_Url+Urls.Share)
                .params("activity_id",activity_id)
                .converter(object :JsonConvert<ShareBean>(){})
                .adapt(ObservableResponse<ShareBean>())
                .subscribeOn(Schedulers.io())
    }
}